package jsyf.oa.web.wechat.service_account.controller;

import jsyf.oa.web.wechat.service_account.utils.CommonUtil;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Test {

    public static void main(String[] args){


        Date date = new Date();
        String result = null;
        SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd");
        result = sdf.format(date);
        String y = getYesterDay(result);
        System.out.println(y);
    }

    public static String getYesterDay(String dateString){
        //通过传过来的时间算出前一天
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        Date dayCurrent = null;
        try {
            dayCurrent = format1.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(dayCurrent);
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        dayCurrent = calendar.getTime();
        return sdf.format(dayCurrent);
    }
}

